package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.entity.StockTakingTask;
import com.wms.service.StockTakingTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "skh-盘点任务")
public class StockTakingTaskController {

    @Autowired
    StockTakingTaskService stockTakingTaskService;

    /**
     * 分页查询未完成的任务列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/stockTakingTask/queryAllNoFinish")
    @ApiOperation(value = "查询未完成任务列表")
    public ResultBean<PageBean<StockTakingTask>> queryAllNoFinish(@RequestParam(value = "page") int page,@RequestParam(value = "pageSize") int pageSize){
        PageBean pageBean =stockTakingTaskService.queryAllNoFinish(page,pageSize);
        if (pageBean!=null){
            return R.success("查询成功",pageBean);
        }
        return R.fail("查询失败");
    }

    /**
     * 分页查询已完成的任务列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/stockTakingTask/queryAllFinish")
    @ApiOperation(value = "查询已完成任务列表")
    public ResultBean<PageBean<StockTakingTask>> queryAllFinish(@RequestParam(value = "page") int page,@RequestParam(value = "pageSize") int pageSize){
        PageBean pageBean =stockTakingTaskService.queryAllFinish(page,pageSize);
        if (pageBean!=null){
            return R.success("查询成功",pageBean);
        }
        return R.fail("查询失败");
    }

    @DeleteMapping("/stockTakingTask/deleteTaskByTaskCode")
    @ApiOperation(value = "删除任务(仅任务状态为待盘点时可删除)")
    public ResultBean deleteTaskByTaskCode(@RequestParam(value = "code") String code){
        int rs =stockTakingTaskService.deleteTaskByTaskCode(code);
        if (rs==1){
            return R.success("删除成功");
        }
        return R.fail("删除失败");
    }

    @PutMapping("/stockTakingTask/updateTaskIscancelByCode")
    @ApiOperation(value = "任务单作废")
    public ResultBean updateTaskIscancelByCode(@RequestParam(value = "code") String code){
        int rs =stockTakingTaskService.updateTaskIscancelByCode(code);
        if (rs==1){
            return R.success("作废成功");
        }
        return R.fail("作废失败");
    }
}
